package logic

import (
	"context"
	"encoding/hex"

	"charging_pile/devices/internal/svc"
	"charging_pile/devices/pb"
	iot "charging_pile/util"
	"charging_pile/util/protocol/jiuxing"

	"github.com/zeromicro/go-zero/core/logx"
)

type StopChargeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStopChargeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StopChargeLogic {
	return &StopChargeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *StopChargeLogic) StopCharge(in *pb.StopChargeReq) (*pb.StopChargeResp, error) {
	// todo: add your logic here and delete this line

	return &pb.StopChargeResp{}, nil
}

func ConvertStopRpc2JxPkg(in *pb.StartChargeReq) *jiuxing.Package {

	pl := jiuxing.Msg26{
		Tm:      iot.FormatJxTime(),
		PlugIdx: 0,
	}
	p := pl.Encode()
	sn, _ := hex.DecodeString(in.Pile)
	pkg := &jiuxing.Package{
		Cmd:        0x1F,
		Sn:         sn,
		Encryption: 1,
		PackageLen: uint16(len(p)),
		Payload:    p,
		Check:      0,
	}

	return pkg
}
